package com.dyypdadmin.controller;

import com.dyypdadmin.pojo.MedicalRecords;
import com.dyypdadmin.result.Result;
import com.dyypdadmin.service.MedicalRecordsService;
import jdk.internal.dynalink.linker.LinkerServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/medicalRecord")
public class MedicalRecordsController {
    @Autowired
    private MedicalRecordsService medicalRecordsService;
    @PostMapping("/addMedicalRecord")
    public Result addMedicalRecord(@RequestBody Map<String,Object> requestBody){
        String order_number= (String) requestBody.get("order_number");
        Integer user_id= (Integer) requestBody.get("user_id");
        String diagnosis_result= (String) requestBody.get("diagnosis_result");
        Integer is_medication_required= (Integer) requestBody.get("is_medication_required");
        String medication_details= (String) requestBody.get("medication_details");
        String doctor_advice= (String) requestBody.get("doctor_advice");
        int result = medicalRecordsService.addMedicalRecord(order_number, user_id, diagnosis_result, is_medication_required, medication_details, doctor_advice);
        if(result>0){
            return new Result(true,"添加成功");
        }else{
            return new Result(false,"添加失败");
        }
    }
    /*
    * 用户根据id获取列表
    *
    * */
    @GetMapping("/getByUserId/{user_id}")
    public Result getByUserId(@PathVariable("user_id")Integer user_id){
        List<MedicalRecords> medicalRecordsList = medicalRecordsService.getByUserId(user_id);
        if(medicalRecordsList!=null){
            return new Result(true,medicalRecordsList);
        }else{
            return new Result(true,"暂时没有您的医疗记录");
        }
    }
    /*
     * 管理端获取列表
     *
     * */
    @GetMapping("/getAll")
    public Result getAll(){
        List<MedicalRecords> medicalRecordsList = medicalRecordsService.getAll();
        if(medicalRecordsList!=null){
            return new Result(true,medicalRecordsList);
        }else{
            return new Result(true,"暂时没有医疗记录");
        }
    }
    /**
     * @description:根据订单号查询诊疗记录
     * @author:邓盈盈
     * @date: 2024/3/8 上午 11:18
     * @param: ordernumber
     * @return:
     **/
    @GetMapping("/getAllMedicalRecordByOrderNumber/{order_number}")
    public Result getAllMedicalRecordByOrderNumbergetAllMedicalRecord(@PathVariable("order_number")String order_number){
        List<MedicalRecords> result =medicalRecordsService.getAllMedicalRecordByOrderNumbergetAllMedicalRecord(order_number);
        if(result!=null){
            return new Result(true,result);
        }else{
            return new Result(false,"fail");
        }

    }
    /**
     * @description:
     * @author:
     * @date: 2024/3/8 下午 09:03
     * @param:
     * @return:
     **/
    @GetMapping("/getMedicalRecordsCounts")
    public Result getMedicalRecordsCounts(){
        int result = medicalRecordsService.getMedicalRecordsCounts();
        return new Result(true,result);

    }
    /**
     * @description: 根据宠物id获取诊疗记录
     * @author:
     * @date: 2024/3/30 上午 05:18
     * @param:
     * @return:
     **/
    @GetMapping("/getAllMedicalRecordsByPetId/{pet_id}")
    public Result getAllMedicalRecordsByPetId(@PathVariable("pet_id")Integer pet_id){
        List<MedicalRecords> result = medicalRecordsService.getAllMedicalRecordsByPetId(pet_id);
        if(result!=null){
            return new Result(true,result);
        }else{
            return new Result(true,"no date");
        }

    }
}
